package com.frank.oj.controller.admin;

import com.frank.model.entity.user.Session;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.admin.system.DashboardService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author frank
 * @Date 2024/3/27
 */
@RestController
@RequestMapping("/api/admin/dashboard")
public class DashboardController {

    @Resource
    private DashboardService dashboardService;

    /**
     * 获取最近的session
     * @return
     */
    @PostMapping("/get-sessions")
    @RequiresAuthentication // 需要认证
    @RequiresRoles(value = {"root","admin","problem_admin"},logical= Logical.OR)
    public CommonResult<Session> getRecentSession(){
        return dashboardService.getRecentSession();
    }

    @GetMapping("/get-dashboard-info")
    @RequiresAuthentication
    @RequiresRoles(value = {"root","admin","problem_admin"},logical= Logical.OR)
    public CommonResult<Map<Object,Object>> getDashboard(){
        return CommonResult.successResponse(dashboardService.getDashboardInfo());
    }
}
